package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Department;
import cn.wolfcode.mapper.DepartmentMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        departmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(Department record) {
//        System.out.println(1);
//        int i=10/0;
        departmentMapper.insert(record);
    }

    @Override
    public void updateByPrimaryKey(Department record) {
        departmentMapper.updateByPrimaryKey(record);
    }



    @Override
    public Department selectByPrimaryKey(Long id) {

        return  departmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Department> selectAll() {

        return  departmentMapper.selectAll();
    }
//分页

    @Override
    public PageInfo<Department> que(QueryObject qo) {
//        分页工具,设置当前页,每页大小
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Department> departments = departmentMapper.selectLimit(qo);
        return new PageInfo<>(departments);
    }

}
